/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.babble.subitem.controller;

import com.babble.blog.vo.BlogVO;
import com.babble.subitem.dto.SubjectItemSaveDTO;
import com.babble.subitem.dto.SubjectItemUpdDTO;
import com.babble.subitem.service.ISubjectItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springblade.common.exception.MsgException;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 专题子项表 控制器
 *
 * @author Blade
 * @since 2021-11-21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/subjectitem")
@Api(value = "专题子项表", tags = "专题子项表接口")
public class SubjectItemController {
	private final ISubjectItemService subjectItemService;
	/**
	 *
	 * @param map
	 * num 页数
	 * size 往后哪几个
	 * @return
	 */
	@ApiOperation(value = "根据专题子项获取分页加时间轴的博客")
	@GetMapping("listSubjectItem")
	public R<List<BlogVO>> listSubjectItem(@RequestParam(required = false) Map<String, Object> map)  {
		List<BlogVO> blogVOs =  subjectItemService.listSubjectItem(map);
		return R.data(blogVOs);
	}
	@ApiOperation(value = "写入子项")
	@PostMapping("save")
	@PreAuth("hasRole('administrator')")
	public R save(@RequestBody SubjectItemSaveDTO subjectItemsavevo) throws MsgException, MsgException {
		subjectItemService.saveSubjectItem(subjectItemsavevo);
		return R.success("添加成功");
	}
	@PreAuth("hasRole('administrator')")
	@ApiOperation(value = "修改专栏子项")
	@PostMapping("upd")
	public R upd(@Valid @RequestBody SubjectItemUpdDTO subjectItemUpdDTO) throws MsgException {
		subjectItemService.updToSubjectItem(subjectItemUpdDTO);
		return R.data("修改成功");
	}
	@PreAuth("hasRole('administrator')")
	@ApiOperation(value = "删除专栏子项")
	@PostMapping("del")
	public R del(@RequestParam("id")String id) throws MsgException {
		subjectItemService.delToSubjectItem(id);
		return R.data("删除成功");
	}
}
